import * as type from '../mutations-types'

export default {
    state: {
        name: '小张'
    },
    mutations: {
        [type.UPDATANAME](state, payload) {
            state.name = payload.name;
        },
        [type.MODULES_ACTIONSUPDATANAME](state, payload) {
            state.name = payload.payloadName;
        },
    },
    actions: {
        modules_actionsUpdataName(context, payload) {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    // context里面还有很多东西的
                    console.log(context);

                    context.commit({
                        type: type.MODULES_ACTIONSUPDATANAME,
                        payloadName: payload.name
                    });

                    resolve('modules里的name被成功修改')
                }, 1000);
            })
        }
    },
    getters: {
        fullName(state) {
            return state.name + '1111';
        },
        fullName2(state, getters) {
            // 第二个参数getters 是modulseA中的getters
            return getters.fullName + '2222';
        },
        fullName3(state, getters, rootstate) {
            // modules中的getters有第三个参数，rootstate表示根的状态
            return getters.fullName2 + rootstate.count;
        },
    }
}